<?php


namespace app\common\lib;

use app\chat\LiveMessage;
use think\Log;
use think\queue\Job;

class LiveSendMsgJob
{
    /**
     * 队列发送直播消息
     * @param Job $job
     * @param $jobData
     * @return void
     */
    public function task(Job $job, $jobData)
    {
        if ($job->attempts() > 1)
        {
            $job->delete();
        }

        //获取
        try
        {
//            LiveMessage::sendMsgNow($jobData['msg'], $jobData['who'], $jobData['msg_type'], $jobData['data'], $jobData['exclude_client_ids']);
            $job->delete();
            print('success');
        }
        catch (\Exception $e)
        {
            Log::write('队列发送直播消息 失败：' . $e->getMessage() . json_encode($jobData) . PHP_EOL . '错误行数：' . '[' . $e->getFile() . ':' . $e->getLine() . ']', 'error', true);
        }

        $jobDataLog = json_encode($jobData, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
        Log::write('队列发送直播消息 结束时间：' . date('Y-m-d H:i:s') . ' $jobDataLog=' . $jobDataLog, 'log', true);
    }
}
